﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Filters;
using YQFK.Helper;

namespace YQFK.Filter
{
    /// <summary>
    /// 异常过滤器
    /// </summary>
    public class ErrorFilter : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext filterContext)
        {
            var url = filterContext.Request.RequestUri.AbsoluteUri;


            var sss = HttpContext.Current.Request.InputStream;
            sss.Seek(0, System.IO.SeekOrigin.Begin);
            byte[] sdfsdf = new byte[sss.Length];
            sss.Read(sdfsdf, 0, sdfsdf.Length);
            string str = System.Text.Encoding.UTF8.GetString(sdfsdf);
            string content = string.Format("{0} {1} \r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "请求地址:" + url.ToLower() + "   所有的参数:" + str);
            WriteLog.AddLog(content);
        }
    }
}